<?php
	class kit_cal_model extends CI_Model{
		private $table = 'medicine_kit_cal';
		function __construct(){
			parent::__construct();
			$this->dbdefault = $this->load->database('passport', true);
		}

		function insert($data){
			$this->dbdefault->insert($this->table, $data);
			return $this->dbdefault->insert_id();
		}

		function selectCode($where = array(), $select =''){
			if(!empty($where)){
				$this->dbdefault->where($where);
			}

			if(!empty($select)){
				$this->dbdefault->select($select);
			}
			return $this->dbdefault->get($this->table)->row_array();
		}
		function selectAllPaging($per,$page){
			return $this->dbdefault->get($this->table,$per)->row_array();
		}
		function doQuery($query){			
			return $this->dbdefault->query($query)->result_array();
		}
		function doInsert($query){
			return $this->dbdefault->query($query);
		}

		function update($data = array(),$where =array()){
			return $this->dbdefault->update($this->table,$data,$where);
		}

		function like($where,$like,$check=''){
			
			$this->dbdefault->where($check);

			$this->dbdefault->like($where,$like);
			
			return $this->dbdefault->get($this->table)->result_array();
		}
		function delete($where){
			return $this->dbdefault->delete($this->table,$where);
		}

		public function get_page_data($where, $perPage, $currentPage, $order_by)
		    {		
		    		$tablename = $this->table;
		    		$db = $this->dbdefault;

			        if(empty($tablename))
			        {
			            return FALSE;
			        }
			        
			        $dbhandle = empty($db) ? $this->db : $db;
			        
			        if($where)
			        {
			            if(is_array($where))
			            {
			                $dbhandle->where($where);
			            }
			            else
			            {
			                $dbhandle->where($where, NULL, false);
			            }
			        }
			        
			        $db = clone($dbhandle);
			        $total = $dbhandle->count_all_results($tablename);
			        
			        if($perPage)
			        {
			            $db->limit($perPage);
			        }
			        
			        if($currentPage)
			        {
			        	$offset = $perPage*($currentPage-1); 
			            $db->offset($offset);
			        }
			        
			        if($order_by)
			        {
			            $db->order_by($order_by,'desc');
			        }
			        
			        $data = $db->get($tablename)->result_array();
			        
			        return array('total' => $total, 'data' => $data);
			    }

			}
?>